package com.tree.leetcode;

/**
 * @ClassName com.tree.leetcode
 * Description: <类功能描述>. <br>
 * <p>
 * 0,1,1,2,3,5,8,13,21
 * </p>
 * @Author tree
 * @Date 2020-03-13 23:52
 * @Version 1.0
 */
public class Fibonacci {
    public static void main(String[] args) {
        System.out.println(fabonacci(7));
        System.out.println(fabonacci2(7));

    }
    public static int fabonacci(int n){
        if(n < 2){
            return n;
        }
        return fabonacci(n-2)+fabonacci(n-1);
    }

    public static int fabonacci2(int n){
        if(n < 2){
            return n;
        }
        int first = 0;
        int second =1;
        int result = 0;
        for(int i=1;i< n;i++){
            result = first+second;
            first = second;
            second =result;
        }
        return result;
    }
}
